package com.woniuxy.tfss.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.tfss.entity.Admin;
import com.woniuxy.tfss.entity.Rider;
import com.woniuxy.tfss.exception.NoAccountException;
import com.woniuxy.tfss.exception.PasswordWrongException;
import com.woniuxy.tfss.mapper.AdminMapper;
import com.woniuxy.tfss.mapper.RiderMapper;
import com.woniuxy.tfss.service.AdminService;
import com.woniuxy.tfss.service.RiderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Autowired(required = false)
    private AdminMapper adminMapper;

    @Override
    public Admin login(String account, String password) {
        QueryWrapper<Admin> wraaper1 = new QueryWrapper<>();
        wraaper1.eq("account", account);
        QueryWrapper<Admin> wraaper2 = new QueryWrapper<>();
        wraaper2.eq("account",account);
        wraaper2.eq("password",password);
        if (adminMapper.selectCount(wraaper1) == 0) {
            throw new NoAccountException("账号不存在！");
        }else{
            if(adminMapper.selectCount(wraaper2)==0){
                throw new PasswordWrongException("密码错误！");
            }else{
                return adminMapper.selectOne(wraaper2);
            }
        }
    }

    @Override
    public void unLock(Admin admin) {
        adminMapper.unLock(admin);
    }
}
